package org.meruvian.yama.service.impl;

import java.util.List;

import org.meruvian.yama.dao.PersonDao;
import org.meruvian.yama.entity.Person;
import org.meruvian.yama.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
*
* @author vick
*/
@Service("personService")
@Transactional(readOnly = true)
public class PersonServiceImpl implements PersonService {
	
	@Autowired 
	private PersonDao personDao;
	
	@Transactional
    public void save(Person person) {
        personDao.save(person);
    }

    @Transactional
    public void delete(Person person) {
        personDao.delete(person);
    }
    
    public Person getPerson(String id){
        return personDao.findById(id);
    }

    public List<Person> getPersons(){
        return personDao.findAll();
    }

    public List<Person> getPersons(int start, int num){
        return personDao.findAll(start, num);
    }
    
    public Person getRelation(String id){
        return personDao.findById(id);
    }
    
    public Person getParent(String id){
        return personDao.findById(id);
    }

    public List<Person> getRelations(){
        return personDao.findAll();
    }
    
    public List<Person> getParents(String id){
        return personDao.getParentC(id);
    }
    
    public List<Person> getChilds(String personId, String relationId){
        return personDao.getChildP(personId, relationId);
    }
    
    public List<Person> listParents(String personId){
        return personDao.listParent(personId);
    }
    
    public List<Person> listChilds(String personId, String parentId){
        return personDao.listChild(personId, parentId);
    }
    
    public List<Person> listPersons(boolean sex){
        return personDao.listPerson(sex);
    }
    
    public List<Person> findPersons(String fristName){
        return personDao.findPerson(fristName);
    }
    
}
